package com.nuanshui.heatedloan.controller.base;

import com.alibaba.dubbo.config.annotation.Reference;
import com.google.common.collect.Maps;
import com.nuanshui.heatedloan.baseservice.facade.ArticleService;
import com.nuanshui.heatedloan.baseservice.vo.ArticleTypeVO;
import com.nuanshui.heatedloan.baseservice.vo.ArticleVO;
import com.nuanshui.heatedloan.constant.GlobalParam;
import com.nuanshui.heatedloan.controller.BaseController;
import com.nuanshui.heatedloan.pageable.Pager;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/article")
public class ArticleController extends BaseController {

    @Reference(url = GlobalParam.BASESERVICE_DUBBO_SERVER, timeout = GlobalParam.DUBBO_SERVER_TIME_OUT,version = GlobalParam.BASESERVICE_DUBBO_SERVER_VERSION)
    private ArticleService articleService;


    @RequestMapping(value = "/list",method = RequestMethod.POST)
    public String list(String catId, Pager<ArticleVO> pager){
        pager = articleService.getArticleListByType(catId,pager);
        return success(pager.asHashMap());
    }

    @RequestMapping(value = "/catList",method = RequestMethod.POST)
    public String catList(@RequestParam(required = true, value = "catIds") List<String> catIds){
        List<ArticleTypeVO> list = articleService.getCatArticleList(catIds);
        return success(list);
    }

    @RequestMapping(value = "/detailById",method = RequestMethod.POST)
    public String detail(String id){
        ArticleVO item = articleService.loadVo(id);
        return success(item);
    }

    @RequestMapping(value = "/detailByAlias",method = RequestMethod.POST)
    public String detailByAlias(String alias){
        ArticleVO item =articleService.loadArticleByAlias(alias);

        return success(item);
    }
}
